package leetcode;

import java.util.Scanner;

/**
 * ClassName: ZhonganT2
 * Package: leetcode
 * Description:
 *
 * @Author wjn
 * @Create 2025/9/12 19:37
 * @Version 1.0
 */
public class ZhonganT2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        long k = scanner.nextLong();
        String s = scanner.next();
        scanner.close();

        int[] prefL = new int[m + 1];
        int[] prefR = new int[m + 1];
        long[] g = new long[m + 1];

        for (int i = 0; i < m; i++) {
            prefL[i + 1] = prefL[i] + (s.charAt(i) == '(' ? 1 : 0);
            prefR[i + 1] = prefR[i] + (s.charAt(i) == ')' ? 1 : 0);
            g[i + 1] = g[i];
            if (s.charAt(i) == ')') {
                g[i + 1] += prefL[i];
            }

        }

        long totalScheme = 0;
        for (int j = 0; j < m; j++) {
            int low = 0, high = j;
            int best_i = -1;
            while (low <= high) {
                int mid_i = low + (high - low) / 2;
                if (calculatePairs(mid_i, j, s, prefL, prefR, g) >= k) {
                    best_i = mid_i;
                    low = mid_i + 1;
                } else {
                    high = mid_i - 1;
                }
            }
            if (best_i != -1) {
                totalScheme += (best_i + 1);
            }

        }
        System.out.println(totalScheme);
    }

    private static long calculatePairs(int i, int j, String s, int[] prefL, int[] prefR, long[] g) {
        long sumPreflAtRight = g[j + 1] - g[i];
        long rightsInSubstring = prefR[j + 1] - prefR[i];
        long leftsBeforeI = prefL[i];

        return sumPreflAtRight - leftsBeforeI * rightsInSubstring;
    }



//    public static void main(String[] args) {
//        Scanner scanner = new Scanner(System.in);
//        int n = scanner.nextInt();
//        int k = scanner.nextInt();
//        scanner.nextLine();
//
//        String s = scanner.nextLine();
//
//        int dp[] = new int[n];
//        int count = 0;
//
//        for (int i = 0; i < n; i++) {
//            if (s.charAt(i) == ')') {
//                dp[i] = 2 + (i >= 2 ? dp[i - 2] : 0);
//            } else if (i - dp[i - 1] - 1 >= 0 && s.charAt(i - dp[i - 1] - 1) == '(') {
//                dp[i] = dp[i - 1] + 2 + ((i - dp[i - 1] - 2 >= 0) ? dp[i - dp[i - 1] - 2] : 0);
//            }
//            if (dp[i] / 2 >= k) {
//                count++;
//            }
//
//        }
//        System.out.println(count);
//    }

}
